<!DOCTYPE html>
<html lang="en">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <style type="text/css">
        html {
            padding: 0;
            width: 100%;
            height: 100%;
            background-color: darkgoldenrod;
        }

        body {
            padding: 0;
            width: 100%;
            height: 100%;
        }

        #container {
            width: 100%;
            height: 100%;
            background-color: aquamarine;
        }

        .title {
            width: 100%;
            height: 30px;
            text-align: center;
        }

        .content {
            display: flex;
            flex-direction: column;
            /* flex: 1; */
            background-color: #ff0000;
            /* width: 100%;
            height: 100%; */
        }

        .flexFunction {
            width: 100%;
            height: 30px;
            background: #00ff00;
            display: flex;
            flex-direction: row;
            justify-content: space-around
        }

        .flexRowItem {
            border: solid 1px;
        }

        .liItem {
            height: 30px;
            background: #00ff00
        }
    </style>
</head>

<body>
    <div id="container">
        <div class="title">ｄｏｍ操作笔记</div>
        <div class="content">
            <div class="flexFunction">
                <div class="flexRowItem">我是元素１</div>
                <div class="flexRowItem">我是元素２</div>
                <div class="flexRowItem">我是元素３</div>
                <div class="flexRowItem">我是元素４</div>
                <div class="flexRowItem">我是元素５</div>
                <div class="flexRowItem">我是元素６</div>
            </div>
            <ul class="subjectUl">
            </ul>
        </div>

    </div>
    <script type="text/javascript">
        var flexFunction = document.getElementsByClassName('flexFunction')
        console.log('doc', flexFunction)
        flexFunction[0].onclick = function () {
            console.log('点击了')
        }
        var ulList = document.getElementsByClassName('subjectUl')
        var ul = ulList[0]
        console.log('ul', ul)
        var subjectList = [{ 'name': '语文' }, { 'name': '数学' }, { 'name': '英文' }, { 'name': '物理' }, { 'name': '化学' }]
        console.log('len', subjectList.length)
        function onItemClick(i) {
            console.log('点击' + i)
        }
        for (let i = 0; i < subjectList.length; i++) {
            console.log('i', i)
            //添加子节点
            //创建子节点
            var li = document.createElement('li')
            li.innerText = subjectList[i].name
            li.className = "liItem"
            //闭包
            li.onclick = function () {
                console.log('ｉｔｅｍ点击', i)
            }
            console.log('li', li)
            //添加节点
            ul.appendChild(li)
        }

    </script>
</body>

</html>